MCPcopy
hub / github.com/zarf-dev/zarf / TestComponentStatus

Function TestComponentStatus

src/test/e2e/37_component_status_test.go:20–93  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestComponentStatus(t *testing.T) {
21 t.Log("E2E: Component Status")
22 tmpDir := t.TempDir()
23 _, _, err := e2e.Zarf(t, "package", "create", "src/test/packages/37-component-status", "-o", tmpDir, "--confirm")
24 require.NoError(t, err)
25 packageName := fmt.Sprintf("zarf-package-component-status-%s.tar.zst", e2e.Arch)
26 path := filepath.Join(tmpDir, packageName)
27 // Stop channel getting the zarf state
28 stop := make(chan bool)
29 // Error channel to return any errors from the goroutine. Testify doesn't like require in a goroutine
30 errCh := make(chan error, 1)
31 var wg sync.WaitGroup
32 wg.Add(1)
33 // Goroutine to wait for the package to show "deploying" status
34 go func() {
35 defer wg.Done()
36 // Give extra time to build and push the package
37 ticker := time.NewTicker(30 * time.Second)
38 for {
39 select {
40 case <-ticker.C:
41 t.Log("Timed out waiting for package to deploy")
42 errCh <- fmt.Errorf("timed out waiting for package to deploy")
43 return
44 case <-stop:
45 return
46 default:
47 stdOut, _, err := e2e.Kubectl(t, "get", "secret", "zarf-package-component-status", "-n", "zarf", "-o", "jsonpath={.data.data}")
48 if err != nil {
49 // Wait for the secret to be created and try again
50 time.Sleep(2 * time.Second)
51 continue
52 }
53 deployedPackage, err := getDeployedPackage(stdOut)
54 if err != nil {
55 errCh <- err
56 return
57 }
58 if len(deployedPackage.DeployedComponents) != 1 {
59 errCh <- fmt.Errorf("expected 1 component got %d", len(deployedPackage.DeployedComponents))
60 return
61 }
62 status := deployedPackage.DeployedComponents[0].Status
63 if status != state.ComponentStatusDeploying {
64 errCh <- fmt.Errorf("expected %s got %s", state.ComponentStatusDeploying, status)
65 return
66 }
67 time.Sleep(2 * time.Second)
68 return
69 }
70 }
71 }()
72 stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--confirm")
73 require.NoError(t, err, stdOut, stdErr)
74 close(stop)
75 wg.Wait()
76 select {
77 case err := <-errCh:

Callers

nothing calls this directly

Calls 5

getDeployedPackageFunction · 0.85
ZarfMethod · 0.80
AddMethod · 0.80
KubectlMethod · 0.80
CleanupMethod · 0.80

Tested by

no test coverage detected