MCPcopy Create free account
hub / github.com/cloudbase/garm / TestValidateInstanceState

Method TestValidateInstanceState

runner/metadata_test.go:1172–1217  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1170}
1171
1172func (s *MetadataTestSuite) TestValidateInstanceState() {
1173 tests := []struct {
1174 name string
1175 ctx context.Context
1176 wantErr bool
1177 }{
1178 {
1179 name: "Valid pending instance",
1180 ctx: s.instanceCtx,
1181 wantErr: false,
1182 },
1183 {
1184 name: "Valid installing instance",
1185 ctx: func() context.Context {
1186 ctx := auth.SetInstanceParams(context.Background(), s.Fixtures.TestInstance)
1187 ctx = auth.SetInstanceRunnerStatus(ctx, params.RunnerInstalling)
1188 return ctx
1189 }(),
1190 wantErr: false,
1191 },
1192 {
1193 name: "Invalid state - active",
1194 ctx: s.invalidInstanceCtx,
1195 wantErr: true,
1196 },
1197 {
1198 name: "Unauthorized - no instance",
1199 ctx: s.unauthorizedCtx,
1200 wantErr: true,
1201 },
1202 }
1203
1204 for _, tt := range tests {
1205 s.Run(tt.name, func() {
1206 instance, err := validateInstanceState(tt.ctx)
1207
1208 if tt.wantErr {
1209 s.Require().NotNil(err)
1210 s.Require().ErrorIs(err, runnerErrors.ErrUnauthorized)
1211 } else {
1212 s.Require().Nil(err)
1213 s.Require().NotEmpty(instance.Name)
1214 }
1215 })
1216 }
1217}
1218
1219func (s *MetadataTestSuite) TestGetJITConfigFileInvalidState() {
1220 ctx := auth.SetInstanceParams(context.Background(), s.Fixtures.TestInstance)

Callers

nothing calls this directly

Calls 4

SetInstanceParamsFunction · 0.92
SetInstanceRunnerStatusFunction · 0.92
validateInstanceStateFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected