Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.13.15 #206

Merged
merged 9 commits into from
Nov 30, 2023
15 changes: 13 additions & 2 deletions index/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,19 @@ func (resolver *Resolver) extractRelatives(ref *Reference, node, parent *yaml.No
def = fmt.Sprintf("%s#/%s", u.String(), exp[1])

} else {
abs, _ := filepath.Abs(filepath.Join(filepath.Dir(ref.FullDefinition), exp[0]))
def = fmt.Sprintf("%s#/%s", abs, exp[1])
z := strings.Split(ref.FullDefinition, "#/")
if len(z) == 2 {
if len(z[0]) > 0 {
abs, _ := filepath.Abs(filepath.Join(filepath.Dir(z[0]), exp[0]))
def = fmt.Sprintf("%s#/%s", abs, exp[1])
} else {
abs, _ := filepath.Abs(exp[0])
def = fmt.Sprintf("%s#/%s", abs, exp[1])
}
} else {
abs, _ := filepath.Abs(filepath.Join(filepath.Dir(ref.FullDefinition), exp[0]))
def = fmt.Sprintf("%s#/%s", abs, exp[1])
}
}
}
} else {
Expand Down
5 changes: 5 additions & 0 deletions index/rolodex.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ func (r *Rolodex) Open(location string) (RolodexFile, error) {
}

if !isUrl {
if len(r.localFS) <= 0 {
r.logger.Warn("[rolodex] no local file systems configured, cannot open local file", "location", location)
return nil, fmt.Errorf("the rolodex has no local file systems configured, cannot open local file '%s'", location)
}

for k, v := range r.localFS {

// check if this is a URL or an abs/rel reference.
Expand Down
1 change: 1 addition & 0 deletions index/rolodex_file_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (l *LocalFS) Open(name string) (fs.File, error) {
l.logger.Debug("[rolodex file loader]: waiting for existing OS load to complete", "file", name, "listeners", wait.listeners)

for !wait.done {
l.logger.Debug("[rolodex file loader]: sleeping for 200ns", "file", name, "listeners", wait.listeners)
time.Sleep(200 * time.Nanosecond) // breathe for a few nanoseconds.
}
wait.listeners--
Expand Down
11 changes: 11 additions & 0 deletions index/rolodex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ func TestRolodex_NoFS(t *testing.T) {

}

func TestRolodex_NoFSButHasRemoteFS(t *testing.T) {

rolo := NewRolodex(CreateOpenAPIIndexConfig())
rolo.AddRemoteFS("http://localhost", nil)
rf, err := rolo.Open("spec.yaml")
assert.Error(t, err)
assert.Equal(t, "the rolodex has no local file systems configured, cannot open local file 'spec.yaml'", err.Error())
assert.Nil(t, rf)

}

func TestRolodex_LocalNativeFS(t *testing.T) {

t.Parallel()
Expand Down
20 changes: 10 additions & 10 deletions index/spec_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve(t *testing.T) {
files := fileFS.GetFiles()
fileLen := len(files)

assert.Equal(t, 1691, fileLen)
assert.Equal(t, 1696, fileLen)

rolo.AddLocalFS(basePath, fileFS)

Expand All @@ -251,18 +251,18 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve(t *testing.T) {

assert.NotNil(t, index)

assert.Len(t, index.GetMappedReferencesSequenced(), 299)
assert.Len(t, index.GetMappedReferences(), 299)
assert.Len(t, index.GetMappedReferencesSequenced(), 300)
assert.Len(t, index.GetMappedReferences(), 300)
assert.Len(t, fileFS.GetErrors(), 0)

// check circular references
rolo.CheckForCircularReferences()
assert.Len(t, rolo.GetCaughtErrors(), 0)
assert.Len(t, rolo.GetIgnoredCircularReferences(), 0)

assert.Equal(t, int64(1328224), rolo.RolodexFileSize())
assert.Equal(t, int64(1331498), rolo.RolodexFileSize())
assert.Equal(t, "1.27 MB", rolo.RolodexFileSizeAsString())
assert.Equal(t, 1691, rolo.RolodexTotalFiles())
assert.Equal(t, 1696, rolo.RolodexTotalFiles())

}

Expand Down Expand Up @@ -317,26 +317,26 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve_RecursiveLookup(t *test
files := fileFS.GetFiles()
fileLen := len(files)

assert.Equal(t, 1677, fileLen)
assert.Equal(t, 1682, fileLen)

assert.NoError(t, rErr)

index := rolo.GetRootIndex()

assert.NotNil(t, index)

assert.Len(t, index.GetMappedReferencesSequenced(), 299)
assert.Len(t, index.GetMappedReferences(), 299)
assert.Len(t, index.GetMappedReferencesSequenced(), 300)
assert.Len(t, index.GetMappedReferences(), 300)
assert.Len(t, fileFS.GetErrors(), 0)

// check circular references
rolo.CheckForCircularReferences()
assert.Len(t, rolo.GetCaughtErrors(), 0)
assert.Len(t, rolo.GetIgnoredCircularReferences(), 0)

assert.Equal(t, int64(1266728), rolo.RolodexFileSize())
assert.Equal(t, int64(1269882), rolo.RolodexFileSize())
assert.Equal(t, "1.21 MB", rolo.RolodexFileSizeAsString())
assert.Equal(t, 1677, rolo.RolodexTotalFiles())
assert.Equal(t, 1682, rolo.RolodexTotalFiles())

}

Expand Down
3 changes: 3 additions & 0 deletions renderer/mock_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (mg *MockGenerator) SetPretty() {
// The name parameter is optional, if provided, the mock generator will attempt to find an example with the given name.
// If no name is provided, the first example will be used.
func (mg *MockGenerator) GenerateMock(mock any, name string) ([]byte, error) {
if mock == nil || !reflect.ValueOf(mock).IsValid() || reflect.ValueOf(mock).IsNil() {
return nil, nil
}
v := reflect.ValueOf(mock).Elem()
num := v.NumField()
fieldCount := 0
Expand Down
12 changes: 12 additions & 0 deletions renderer/mock_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ func TestNewMockGeneratorWithDictionary(t *testing.T) {
assert.NotNil(t, mg)
}

func TestMockGenerator_GenerateJSONMock_NoObject(t *testing.T) {

mg := NewMockGenerator(JSON)

var isNil any
isNil = nil

mock, err := mg.GenerateMock(isNil, "")
assert.NoError(t, err)
assert.Nil(t, mock)
}

func TestMockGenerator_GenerateJSONMock_BadObject(t *testing.T) {
type NotMockable struct {
pizza string
Expand Down
32 changes: 32 additions & 0 deletions what-changed/model/security_requirement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,38 @@ biscuit:
assert.Equal(t, 1, extChanges.TotalBreakingChanges())
}

// codecov seems to get upset with this not being covered.
// so lets run the damn thing a few hundred thousand times.
func BenchmarkCompareSecurityRequirement_Remove(b *testing.B) {

left := `auth:
- pizza
- pie`

right := `auth:
- pie
- pizza
biscuit:
- digestive`

var lNode, rNode yaml.Node
_ = yaml.Unmarshal([]byte(left), &lNode)
_ = yaml.Unmarshal([]byte(right), &rNode)

for i := 0; i < b.N; i++ {
var lDoc base.SecurityRequirement
var rDoc base.SecurityRequirement
_ = low.BuildModel(lNode.Content[0], &lDoc)
_ = low.BuildModel(rNode.Content[0], &rDoc)
_ = lDoc.Build(context.Background(), nil, lNode.Content[0], nil)
_ = rDoc.Build(context.Background(), nil, rNode.Content[0], nil)
extChanges := CompareSecurityRequirement(&rDoc, &lDoc)
assert.Equal(b, 1, extChanges.TotalChanges())
assert.Len(b, extChanges.GetAllChanges(), 1)
assert.Equal(b, 1, extChanges.TotalBreakingChanges())
}
}

func TestCompareSecurityRequirement_SwapOut_V2(t *testing.T) {

left := `cheese:
Expand Down