Skip to content

Commit

Permalink
improve unit test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Aug 10, 2024
1 parent 85ee075 commit acc142e
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions schema/enum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package schema

import (
"encoding/json"
"fmt"
"testing"
)

func TestSchemaSpecType(t *testing.T) {
rawValue := "oas2"
var got SchemaSpecType
if err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, rawValue)), &got); err != nil {
t.Fatalf(err.Error())
}
if got != SchemaSpecType(rawValue) {
t.Fatalf("expected %s, got: %s", rawValue, got)
}
if got.JSONSchema().Type != "string" {
t.Fatalf("expected string, got: %s", got.JSONSchema().Type)
}
}

func TestRequestType(t *testing.T) {
rawValue := "rest"
var got RequestType
if err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, rawValue)), &got); err != nil {
t.Fatalf(err.Error())
}
if got != RequestType(rawValue) {
t.Fatalf("expected %s, got: %s", rawValue, got)
}
}

func TestSchemaFileFormat(t *testing.T) {
rawValue := "yaml"
var got SchemaFileFormat
if err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, rawValue)), &got); err != nil {
t.Fatalf(err.Error())
}
if got != SchemaFileFormat(rawValue) {
t.Fatalf("expected %s, got: %s", rawValue, got)
}
if got.JSONSchema().Type != "string" {
t.Fatalf("expected string, got: %s", got.JSONSchema().Type)
}
}

func TestParameterLocation(t *testing.T) {
rawValue := "cookie"
var got ParameterLocation
if err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, rawValue)), &got); err != nil {
t.Fatalf(err.Error())
}
if got != ParameterLocation(rawValue) {
t.Fatalf("expected %s, got: %s", rawValue, got)
}
if got.JSONSchema().Type != "string" {
t.Fatalf("expected string, got: %s", got.JSONSchema().Type)
}
}

func TestParameterEncodingStyle(t *testing.T) {
rawValue := "matrix"
var got ParameterEncodingStyle
if err := json.Unmarshal([]byte(fmt.Sprintf(`"%s"`, rawValue)), &got); err != nil {
t.Fatalf(err.Error())
}
if got != ParameterEncodingStyle(rawValue) {
t.Fatalf("expected %s, got: %s", rawValue, got)
}
if got.JSONSchema().Type != "string" {
t.Fatalf("expected string, got: %s", got.JSONSchema().Type)
}
}

0 comments on commit acc142e

Please sign in to comment.