blob: 0788b5e959f669e3d76f93b97e3faf6fa8a14170 [file] [log] [blame]
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "utility.hpp"
#include <flashupdate/info.hpp>
#include <flashupdate/ops.hpp>
#include <nlohmann/json.hpp>
#include <format>
#include <string>
#include <gtest/gtest.h>
namespace flashupdate
{
TEST_F(OperationTest, UpdateStateInvalidState)
{
Args args;
args.state = "FAKE_STATE";
EXPECT_THROW(
try { ops::updateState(args); } catch (const std::runtime_error& e) {
EXPECT_STREQ(
e.what(),
std::format(
"{} is not a supported state. Need to be one of\n{}",
args.state, info::listStates())
.c_str());
throw;
},
std::runtime_error);
}
TEST_F(OperationTest, UpdateStatePass)
{
std::string filename = "/tmp/update_state_eeprom-XXXXXX";
resetInfo();
Args args;
nlohmann::json expectedOutput;
args.checkStageState = true;
args.state = "STAGED";
createFakeEeprom(args, filename);
expectedOutput["Staged State"] = "STAGED";
EXPECT_EQ(ops::updateState(args), expectedOutput.dump());
}
} // namespace flashupdate