Skip to content

Commit

Permalink
wip: define specs
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jun 16, 2023
1 parent 3d5a025 commit fb249d5
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 81 deletions.
22 changes: 15 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ module github.com/ipfs/gateway-conformance
go 1.20

require (
github.com/ipfs/boxo v0.8.2-0.20230510114019-33e3f0cd052b
github.com/ipfs/boxo v0.10.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-unixfsnode v1.6.0
github.com/ipfs/go-unixfsnode v1.7.1
github.com/ipld/go-car v0.6.1
github.com/ipld/go-car/v2 v2.9.1-0.20230325062757-fff0e4397a3d
github.com/ipld/go-codec-dagpb v1.6.0
github.com/ipld/go-ipld-prime v0.20.0
github.com/libp2p/go-libp2p v0.26.3
github.com/stretchr/testify v1.8.2
github.com/stretchr/testify v1.8.4
github.com/urfave/cli/v2 v2.25.3
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -19,7 +22,12 @@ require (
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/ipld/go-codec-dagpb v1.6.0 // indirect
github.com/ipfs/go-blockservice v0.5.0 // indirect
github.com/ipfs/go-ipfs-blockstore v1.3.0 // indirect
github.com/ipfs/go-ipfs-ds-help v1.1.0 // indirect
github.com/ipfs/go-ipfs-exchange-interface v0.2.0 // indirect
github.com/ipfs/go-merkledag v0.11.0 // indirect
github.com/ipfs/go-verifcid v0.0.2 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p-record v0.2.0 // indirect
github.com/multiformats/go-multiaddr v0.8.0 // indirect
Expand All @@ -43,8 +51,8 @@ require (
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
github.com/ipfs/go-ipld-cbor v0.0.6 // indirect
github.com/ipfs/go-ipld-format v0.4.0
github.com/ipfs/go-ipld-legacy v0.1.1 // indirect
github.com/ipfs/go-ipld-format v0.5.0
github.com/ipfs/go-ipld-legacy v0.2.1 // indirect
github.com/ipfs/go-log v1.0.5
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
Expand All @@ -57,7 +65,7 @@ require (
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/multiformats/go-multibase v0.2.0
github.com/multiformats/go-multicodec v0.9.0
github.com/multiformats/go-multihash v0.2.1
github.com/multiformats/go-multihash v0.2.3
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
Expand Down
68 changes: 31 additions & 37 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/t0109_gateway_web_redirects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func TestRedirectsFileSupportWithDNSLink(t *testing.T) {
RunIfSpecsAreEnabled(
t,
helpers.UnwrapSubdomainTests(t, tests),
specs.DNSLinkResolver,
specs.DNSLinkGateway,
specs.SubdomainGateway,
)
}
2 changes: 1 addition & 1 deletion tests/t0114_gateway_subdomains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,5 +741,5 @@ func TestGatewaySubdomainAndDnsLink(t *testing.T) {
}...)
}

RunIfSpecsAreEnabled(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGateway, specs.DNSLinkResolver)
RunIfSpecsAreEnabled(t, helpers.UnwrapSubdomainTests(t, tests), specs.SubdomainGateway, specs.DNSLinkGateway)
}
2 changes: 1 addition & 1 deletion tests/t0115_gateway_dir_listing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,6 @@ func TestDirListingOnDNSLinkGateway(t *testing.T) {
tests,
),
specs.SubdomainGateway,
specs.DNSLinkResolver,
specs.DNSLinkGateway,
)
}
2 changes: 1 addition & 1 deletion tooling/car/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"fmt"

"github.com/ipfs/boxo/ipld/car/v2/blockstore"
"github.com/ipfs/go-cid"
"github.com/ipld/go-car/v2/blockstore"
)

func Merge(inputPaths []string, outputPath string) error {
Expand Down
2 changes: 1 addition & 1 deletion tooling/car/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
"sync"

"github.com/ipfs/boxo/blockservice"
"github.com/ipfs/boxo/ipld/car/v2/blockstore"
"github.com/ipfs/boxo/ipld/merkledag"
"github.com/ipfs/boxo/ipld/unixfs"
"github.com/ipfs/boxo/ipld/unixfs/hamt"
uio "github.com/ipfs/boxo/ipld/unixfs/io"
"github.com/ipfs/go-cid"
format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-unixfsnode"
"github.com/ipld/go-car/v2/blockstore"
dagpb "github.com/ipld/go-codec-dagpb"
"github.com/ipld/go-ipld-prime"
_ "github.com/ipld/go-ipld-prime/codec/cbor"
Expand Down
4 changes: 2 additions & 2 deletions tooling/check/cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"io"

"github.com/ipfs/boxo/ipld/car"
"github.com/ipfs/boxo/ipld/car/v2/blockstore"
"github.com/ipfs/go-cid"
"github.com/ipld/go-car"
"github.com/ipld/go-car/v2/blockstore"
)

func CidSetContains(a, b []cid.Cid) CheckOutput {
Expand Down
120 changes: 91 additions & 29 deletions tooling/specs/specs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package specs

import (
"fmt"
)
import "fmt"

type maturity string

Expand All @@ -24,58 +22,122 @@ func (m maturity) isMature() bool {
}
}

type Spec string

const (
SubdomainGateway Spec = "subdomain-gateway"
DNSLinkResolver Spec = "dnslink-resolver"
IPNSResolver Spec = "ipns-resolver"
)
type Spec interface {
Name() string
IsEnabled() bool
IsMature() bool
Enable()
Disable()
}

// All specs should be listed here.
var specMaturity = map[Spec]maturity{
SubdomainGateway: stable,
DNSLinkResolver: stable,
IPNSResolver: stable,
type Leaf struct {
name string
maturity maturity
}

func (s Spec) IsMature() bool {
return specMaturity[s].isMature()
func (l Leaf) Name() string {
return l.name
}

var specEnabled = map[Spec]bool{}
func (l Leaf) IsMature() bool {
return l.maturity.isMature()
}

func (s Spec) IsEnabled() bool {
func (l Leaf) IsEnabled() bool {
// If the spec was explicitly enabled or disabled, use that.
// Otherwise, use the maturity level.
if enabled, ok := specEnabled[s]; ok {
if enabled, ok := specEnabled[l]; ok {
return enabled
} else {
return s.IsMature()
return l.IsMature()
}
}

func (s Spec) Enable() {
func (s Leaf) Enable() {
specEnabled[s] = true
}

func (s Spec) Disable() {
func (s Leaf) Disable() {
specEnabled[s] = false
}

func All() []Spec {
specs := []Spec{}
for spec := range specMaturity {
specs = append(specs, spec)
type Collection struct {
name string
children []Spec
}

func (c Collection) Name() string {
return c.name
}

func (c Collection) IsEnabled() bool {
for _, s := range c.children {
if !s.IsEnabled() {
return false
}
}

return true
}

func (c Collection) IsMature() bool {
for _, s := range c.children {
if !s.IsMature() {
return false
}
}

return true
}

func (c Collection) Enable() {
for _, s := range c.children {
s.Enable()
}
}

func (c Collection) Disable() {
for _, s := range c.children {
s.Disable()
}
}

var (
TrustlessBlockGateway = Leaf{"trustless-block-gateway", stable}
TrustlessCARGateway = Leaf{"trustless-car-gateway", stable}
TrustlessIPNSGateway = Leaf{"trustless-ipns-gateway", stable}
TrustlessGateway = Collection{"trustless-gateway", []Spec{TrustlessBlockGateway, TrustlessCARGateway, TrustlessIPNSGateway}}
PathGateway = Leaf{"path-gateway", stable}
DNSLinkGateway = Leaf{"dnslink-gateway", stable}
SubdomainGateway = Leaf{"subdomain-gateway", stable}
RedirectsFile = Leaf{"redirects-file", stable} // TODO: Can be run for path gateway, dnslink and subdomain gateways, but not by itself.
IPNSResolver = Leaf{"ipns-resolver", stable}
)

// All specs MUST be listed here.
var specs = []Spec{
TrustlessBlockGateway,
TrustlessCARGateway,
TrustlessIPNSGateway,
TrustlessGateway,
PathGateway,
DNSLinkGateway,
SubdomainGateway,
RedirectsFile,
IPNSResolver,
}

var specEnabled = map[Spec]bool{}

func All() []Spec {
return specs
}

func FromString(name string) (Spec, error) {
for _, spec := range All() {
if string(spec) == name {
if spec.Name() == name {
return spec, nil
}
}
return "", fmt.Errorf("unknown spec: %s", name)
return nil, fmt.Errorf("unknown spec: %s", name)
}
2 changes: 1 addition & 1 deletion tooling/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SugarTests []SugarTest
func RunIfSpecsAreEnabled(
t *testing.T,
tests SugarTests,
required ...specs.Spec,
required ...specs.Leaf,
) {
t.Helper()

Expand Down

0 comments on commit fb249d5

Please sign in to comment.