115 lines
6.3 KiB
Go
115 lines
6.3 KiB
Go
package harness
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-contracts/provisioning/go/clients/meshprovisionerclient/provider"
|
|
)
|
|
|
|
// TestHarnessRuns groups the cases below, each one a subtest.
|
|
func TestHarnessRuns(t *testing.T) {
|
|
// TestHarness holds this file's cases, each a subtest of its own name (mesh-sdk's test budget: at most 500 unit tests).
|
|
t.Run("Harness", func(t *testing.T) {
|
|
t.Run("AConsumerIsCreatedOnceUnderTheMeshsLoginAndPassword", testAConsumerIsCreatedOnceUnderTheMeshsLoginAndPassword)
|
|
t.Run("AConsumerNoLongerAskedForIsRetiredOnceStable", testAConsumerNoLongerAskedForIsRetiredOnceStable)
|
|
t.Run("NothingReadIsNotNobodyAsking", testNothingReadIsNotNobodyAsking)
|
|
t.Run("ALostConsumerIsAppliedAgainAndBraked", testALostConsumerIsAppliedAgainAndBraked)
|
|
t.Run("AFailingCreateIsRetriedAndSaidOnce", testAFailingCreateIsRetriedAndSaidOnce)
|
|
t.Run("ScrubRemovesThePassword", testScrubRemovesThePassword)
|
|
})
|
|
|
|
t.Run("AMovedPathStartedTooEarlyAsksAgainUntilTheRuntimeAnswers", func(t *testing.T) {
|
|
w := newMovedWorld(t, map[[2]string]string{})
|
|
w.run.FirstRetry = time.Millisecond
|
|
w.run.loaded = false
|
|
bus := &earlyBus{bucketBus: w.bus, refuse: 3}
|
|
p := provider.New(provider.Options{Node: "novox", Module: "postgres", Bus: w.bus,
|
|
Vault: provider.ConsumersFile{Paths: []string{w.file}}, Make: w.run.Make, Gone: w.run.Gone,
|
|
Every: time.Hour, Logf: func(string, ...any) {}})
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
done := make(chan error, 1)
|
|
go func() { done <- w.run.Run(ctx, p, bus) }()
|
|
deadline := time.After(time.Second)
|
|
for {
|
|
w.run.mu.Lock()
|
|
loaded := w.run.loaded
|
|
w.run.mu.Unlock()
|
|
if loaded {
|
|
break
|
|
}
|
|
select {
|
|
case err := <-done:
|
|
cancel()
|
|
t.Fatalf("Run stopped before the runtime answered: %v", err)
|
|
case <-deadline:
|
|
cancel()
|
|
t.Fatal("the plans were never watched")
|
|
case <-time.After(time.Millisecond):
|
|
}
|
|
}
|
|
cancel()
|
|
<-done
|
|
if bus.refuse != 0 {
|
|
t.Fatalf("%d refusals left", bus.refuse)
|
|
}
|
|
})
|
|
|
|
// TestStanding holds this file's cases, each a subtest of its own name (mesh-sdk's test budget: at most 500 unit tests).
|
|
t.Run("Standing", func(t *testing.T) {
|
|
t.Run("AConsumerFailedForMinutesIsAnnouncedNamingItAndTheClass", testAConsumerFailedForMinutesIsAnnouncedNamingItAndTheClass)
|
|
t.Run("OneSuccessBetweenFailuresStartsTheRunAgain", testOneSuccessBetweenFailuresStartsTheRunAgain)
|
|
t.Run("ACheckThatKeepsFailingIsAFailureToo", testACheckThatKeepsFailingIsAFailureToo)
|
|
t.Run("AnUnreadableSecretIsAnnouncedAsSuch", testAnUnreadableSecretIsAnnouncedAsSuch)
|
|
t.Run("AConsumerNoLongerAskedForIsNoLongerFailing", testAConsumerNoLongerAskedForIsNoLongerFailing)
|
|
t.Run("AnErrorIsClassedByItsWords", testAnErrorIsClassedByItsWords)
|
|
t.Run("AnAdapterThatClassesItsOwnErrorsIsBelieved", testAnAdapterThatClassesItsOwnErrorsIsBelieved)
|
|
t.Run("TheFirstSuccessSinceStartIsAnnouncedOnce", testTheFirstSuccessSinceStartIsAnnouncedOnce)
|
|
})
|
|
}
|
|
|
|
// TestHarnessMoves groups the cases below, each one a subtest.
|
|
func TestHarnessMoves(t *testing.T) {
|
|
// TestMoved holds this file's cases, each a subtest of its own name (mesh-sdk's test budget: at most 500 unit tests).
|
|
t.Run("Moved", func(t *testing.T) {
|
|
t.Run("TheConsumersFileMakesWhatTheGrantFilesMake", testTheConsumersFileMakesWhatTheGrantFilesMake)
|
|
t.Run("AConsumerMissingFromOneReadRetiresNothing", testAConsumerMissingFromOneReadRetiresNothing)
|
|
t.Run("NoPlansReadRetiresNothing", testNoPlansReadRetiresNothing)
|
|
t.Run("AConsumerWithoutACredentialIsWaitedFor", testAConsumerWithoutACredentialIsWaitedFor)
|
|
t.Run("ASluggedConsumerKeepsTheLoginItsPlanNames", testASluggedConsumerKeepsTheLoginItsPlanNames)
|
|
t.Run("ASpecWithoutGrantsMakesUnderThePlansAsAndIgnoresTheGrantFile", testASpecWithoutGrantsMakesUnderThePlansAsAndIgnoresTheGrantFile)
|
|
t.Run("TheConsumersFileMakesWhatTheGrantFileMakesForTheKeycloakShape", testTheConsumersFileMakesWhatTheGrantFileMakesForTheKeycloakShape)
|
|
t.Run("AConsumerNamedByItsPlanKeepsItsClientId", testAConsumerNamedByItsPlanKeepsItsClientId)
|
|
})
|
|
|
|
// TestGrantsMoved holds this file's cases, each a subtest of its own name (mesh-sdk's test budget: at most 500 unit tests).
|
|
t.Run("GrantsMoved", func(t *testing.T) {
|
|
t.Run("AConsumerOnlyTheGrantFileGivesIsAskedForAndMade", testAConsumerOnlyTheGrantFileGivesIsAskedForAndMade)
|
|
t.Run("ALoginAPlanNamesIsNotMadeFromTheGrantFile", testALoginAPlanNamesIsNotMadeFromTheGrantFile)
|
|
t.Run("AnUnreadableGrantFileRetiresNothing", testAnUnreadableGrantFileRetiresNothing)
|
|
t.Run("ALoginTheGrantFileStopsGivingIsRetired", testALoginTheGrantFileStopsGivingIsRetired)
|
|
})
|
|
|
|
// TestRetirement holds this file's cases, each a subtest of its own name (mesh-sdk's test budget: at most 500 unit tests).
|
|
t.Run("Retirement", func(t *testing.T) {
|
|
t.Run("ATransientEmptyListForFourPassesRetiresNothing", testATransientEmptyListForFourPassesRetiresNothing)
|
|
t.Run("FivePassesInTwentyFiveSecondsRetireNothingTenMinutesDo", testFivePassesInTwentyFiveSecondsRetireNothingTenMinutesDo)
|
|
t.Run("AStableSetIsRetiredAndAskedAgainReEnables", testAStableSetIsRetiredAndAskedAgainReEnables)
|
|
t.Run("AnUnreadablePassStartsTheCountAgain", testAnUnreadablePassStartsTheCountAgain)
|
|
t.Run("ADifferentSetStartsTheCountAgain", testADifferentSetStartsTheCountAgain)
|
|
t.Run("AdditionsAndChangesAreNeverDelayed", testAdditionsAndChangesAreNeverDelayed)
|
|
t.Run("TooManyWaitsForAPersonAndApproveRetiresExactlyThatSet", testTooManyWaitsForAPersonAndApproveRetiresExactlyThatSet)
|
|
t.Run("RejectedIsKeptAndNotAskedAgainUntilTheSetChanges", testRejectedIsKeptAndNotAskedAgainUntilTheSetChanges)
|
|
t.Run("AWaitingSetAskedForAgainSettles", testAWaitingSetAskedForAgainSettles)
|
|
t.Run("DeleteRemovesOnlyThatRetiredConsumer", testDeleteRemovesOnlyThatRetiredConsumer)
|
|
t.Run("TheBound", testTheBound)
|
|
t.Run("ARestartRetiresWhatTheBackendHoldsUnaskedAndAdoptsWhatItFindsDisabled", testARestartRetiresWhatTheBackendHoldsUnaskedAndAdoptsWhatItFindsDisabled)
|
|
t.Run("ABackendThatCannotBeListedIsSaidAndAskedAgain", testABackendThatCannotBeListedIsSaidAndAskedAgain)
|
|
t.Run("TheToolsAnswer", testTheToolsAnswer)
|
|
t.Run("AFailingConsumerRetiredIsSaidRecovered", testAFailingConsumerRetiredIsSaidRecovered)
|
|
t.Run("ARestartedProviderSaysOnceThatNothingWaits", testARestartedProviderSaysOnceThatNothingWaits)
|
|
t.Run("AProviderThatWaitsDoesNotSayNothingWaits", testAProviderThatWaitsDoesNotSayNothingWaits)
|
|
})
|
|
}
|