File: delete_test.go

package info (click to toggle)
golang-github-apptainer-container-library-client 1.4.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 384 kB
  • sloc: makefile: 5
file content (72 lines) | stat: -rw-r--r-- 1,479 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package client

import (
	"context"
	"fmt"
	"net/http"
	"testing"
)

func Test_DeleteImage(t *testing.T) {
	tests := []struct {
		name        string
		imageRef    string
		arch        string
		expectError bool
		code        int
		callback    func(*http.Request, *testing.T)
	}{
		{
			name:        "MissingImageRefAndArch",
			expectError: true,
		},
		{
			name:        "MissingImageRef",
			arch:        archIntel,
			expectError: true,
		},
		{
			name:        "MissingArch",
			imageRef:    "test:v0.0.1",
			expectError: true,
		},
		{
			name:     "ValidateQueryStringArch",
			imageRef: "test",
			arch:     archIntel,
			code:     http.StatusOK,
			callback: func(r *http.Request, t *testing.T) {
				// ensure arch specified in query string is as expected
				queryArch := r.URL.Query().Get("arch")
				if queryArch != archIntel {
					t.Errorf("got arch %v, want %v", queryArch, archIntel)
				}
			},
		},
	}

	for _, tt := range tests {
		tt := tt

		t.Run(tt.name, func(t *testing.T) {
			m := mockService{
				t:           t,
				code:        tt.code,
				httpPath:    fmt.Sprintf("/v1/images/%s", tt.imageRef),
				reqCallback: tt.callback,
			}
			m.Run()
			defer m.Stop()

			c, err := NewClient(&Config{BaseURL: m.baseURI})
			if err != nil {
				t.Errorf("Error initializing client: %v", err)
			}

			err = c.DeleteImage(context.Background(), tt.imageRef, tt.arch)
			if !tt.expectError && err != nil {
				t.Errorf("Unexpected err: %s", err)
			}
		})
	}
}