Skip to content

Commit

Permalink
Adds imageInspectParserFilter_test
Browse files Browse the repository at this point in the history
  • Loading branch information
bomoko committed Feb 6, 2024
1 parent b3bce5b commit 56ae401
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions internal/handler/imageInspectParserFilter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package handler

import (
"encoding/json"
"fmt"
"log/slog"
"os"
"testing"
)

func Test_processFactsFromImageInspect(t *testing.T) {
type args struct {
logger *slog.Logger
imageInspectDataSource string
id int
source string
}
tests := []struct {
name string
args args
contains []LagoonFact
wantErr bool
}{
{
name: "Testing Environment Variables",
args: args{
logger: slog.Default(),
imageInspectDataSource: "testassets/imageInspectParserFilter/test1_envtesting.json",
id: 0,
source: "service",
},
contains: []LagoonFact{
{
Name: "PYTHON_PIP_VERSION",
Value: "1",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

imageInspectBytes, err := os.ReadFile(tt.args.imageInspectDataSource)
if err != nil {
slog.Error("Failed opening test file")
panic(1)
}

imageInspectData := ImageData{}

err = json.Unmarshal(imageInspectBytes, &imageInspectData)
if err != nil {
slog.Error(err.Error())
panic(1)
}

got, err := processFactsFromImageInspect(tt.args.logger, imageInspectData, tt.args.id, tt.args.source)
if (err != nil) != tt.wantErr {
t.Errorf("processFactsFromImageInspect() error = %v, wantErr %v", err, tt.wantErr)
return
}

fmt.Println(got)

for _, v := range tt.contains {
found := false
for _, f := range got {
if v.Name == f.Name && v.Value == f.Value {
found = true
break
}
}
if !found {
t.Errorf("processFactsFromImageInspect() could not find target values in data loaded from file")
}
}
})
}
}

0 comments on commit 56ae401

Please sign in to comment.