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

Update Module Path, XML NodeDecoder Fixes #245

Merged
merged 4 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class SmithyGoDependency {

public static final GoDependency GO_JMESPATH = goJmespath(null);

private static final String SMITHY_SOURCE_PATH = "github.com/awslabs/smithy-go";
private static final String SMITHY_SOURCE_PATH = "github.com/aws/smithy-go";
private static final String GO_CMP_SOURCE_PATH = "github.com/google/go-cmp";
private static final String GO_JMESPATH_SOURCE_PATH = "github.com/jmespath/go-jmespath";

Expand Down Expand Up @@ -118,7 +118,7 @@ private static GoDependency relativePackage(
private static final class Versions {
private static final String GO_STDLIB = "1.15";
private static final String GO_CMP = "v0.5.4";
private static final String SMITHY_GO = "v0.4.1-0.20201216214517-20e212c92831";
private static final String SMITHY_GO = "v0.4.1-0.20201222001052-74df8ddd8c79";
private static final String GO_JMESPATH = "v0.4.0";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ public void testStandardLibraryDependency() {
public void testSingleDependency() {
GoDependency dependency = GoDependency.builder()
.type(GoDependency.Type.DEPENDENCY)
.sourcePath("github.com/awslabs/smithy-go")
.importPath("github.com/awslabs/smithy-go/middleware")
.sourcePath("github.com/aws/smithy-go")
.importPath("github.com/aws/smithy-go/middleware")
.version("1.2.3")
.build();
List<SymbolDependency> symbolDependencies = dependency.getDependencies();
assertThat(symbolDependencies.size(), Matchers.equalTo(1));
SymbolDependency symbolDependency = symbolDependencies.get(0);

assertThat(symbolDependency.getDependencyType(), Matchers.equalTo("dependency"));
assertThat(symbolDependency.getPackageName(), Matchers.equalTo("github.com/awslabs/smithy-go"));
assertThat(symbolDependency.getPackageName(), Matchers.equalTo("github.com/aws/smithy-go"));
assertThat(symbolDependency.getVersion(), Matchers.equalTo("1.2.3"));
}

Expand All @@ -66,8 +66,8 @@ public void testDependencyWithDependencies() {
.version("1.2.3")
.addDependency(GoDependency.builder()
.type(GoDependency.Type.DEPENDENCY)
.sourcePath("github.com/awslabs/smithy-go")
.importPath("github.com/awslabs/smithy-go/middleware")
.sourcePath("github.com/aws/smithy-go")
.importPath("github.com/aws/smithy-go/middleware")
.version("3.4.5")
.build())
.build();
Expand All @@ -81,7 +81,7 @@ public void testDependencyWithDependencies() {
.build()),
Matchers.equalTo(SymbolDependency.builder()
.dependencyType("dependency")
.packageName("github.com/awslabs/smithy-go")
.packageName("github.com/aws/smithy-go")
.version("3.4.5")
.build())
));
Expand All @@ -96,8 +96,8 @@ public void testDependencyWithNestedDependencies() {
.version("1.2.3")
.addDependency(GoDependency.builder()
.type(GoDependency.Type.DEPENDENCY)
.sourcePath("github.com/awslabs/smithy-go")
.importPath("github.com/awslabs/smithy-go/middleware")
.sourcePath("github.com/aws/smithy-go")
.importPath("github.com/aws/smithy-go/middleware")
.version("3.4.5")
.addDependency(GoDependency.builder()
.type(GoDependency.Type.DEPENDENCY)
Expand Down Expand Up @@ -128,7 +128,7 @@ public void testDependencyWithNestedDependencies() {
.build()),
Matchers.equalTo(SymbolDependency.builder()
.dependencyType("dependency")
.packageName("github.com/awslabs/smithy-go")
.packageName("github.com/aws/smithy-go")
.version("3.4.5")
.build()),
Matchers.equalTo(SymbolDependency.builder()
Expand Down
3 changes: 2 additions & 1 deletion encoding/json/decoder_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package json
import (
"bytes"
"encoding/json"
smithytesting "github.com/awslabs/smithy-go/testing"
"testing"

smithytesting "github.com/aws/smithy-go/testing"
)

func TestDiscardUnknownField(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"testing"

"github.com/awslabs/smithy-go/encoding/json"
"github.com/aws/smithy-go/encoding/json"
)

func TestEncoder(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion encoding/json/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"
"strconv"

"github.com/awslabs/smithy-go/encoding"
"github.com/aws/smithy-go/encoding"
)

// Value represents a JSON Value type
Expand Down
2 changes: 1 addition & 1 deletion encoding/xml/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"testing"

"github.com/awslabs/smithy-go/encoding/xml"
"github.com/aws/smithy-go/encoding/xml"
)

var root = xml.StartElement{Name: xml.Name{Local: "root"}}
Expand Down
2 changes: 1 addition & 1 deletion encoding/xml/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"math/big"
"strconv"

"github.com/awslabs/smithy-go/encoding"
"github.com/aws/smithy-go/encoding"
)

// Value represents an XML Value type
Expand Down
55 changes: 46 additions & 9 deletions encoding/xml/xml_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xml
import (
"encoding/xml"
"fmt"
"strings"
)

// NodeDecoder is a XML decoder wrapper that is responsible to decoding
Expand Down Expand Up @@ -43,31 +44,67 @@ func (d NodeDecoder) Token() (t xml.StartElement, done bool, err error) {
// skip token if it is a comment or preamble or empty space value due to indentation
// or if it's a value and is not expected
}
}

return
// GetElement looks for the given tag name at the current level, and returns the element if found, and
// skipping over non-matching elements. Returns an error if the node is not found, or if an error occurs while walking
// the document.
func (d NodeDecoder) GetElement(name string) (t xml.StartElement, err error) {
for {
token, done, err := d.Token()
if err != nil {
return t, err
}
if done {
return t, fmt.Errorf("%s node not found", name)
}
switch {
case strings.EqualFold(name, token.Name.Local):
return token, nil
default:
err = d.Decoder.Skip()
if err != nil {
return t, err
}
}
}
}

// Value provides an abstraction to retrieve char data value within an xml element.
// The method will return an error if it encounters a nested xml element instead of char data.
// This method should only be used to retrieve simple type or blob shape values as []byte.
func (d NodeDecoder) Value() (c []byte, done bool, err error) {
func (d NodeDecoder) Value() (c []byte, err error) {
t, e := d.Decoder.Token()
if e != nil {
return c, done, e
return c, e
}

// check if token is of type charData
if ev, ok := t.(xml.CharData); ok {
return ev, done, err
endElement := d.StartEl.End()

switch ev := t.(type) {
case xml.CharData:
c = ev.Copy()
case xml.EndElement: // end tag or self-closing
if ev == endElement {
return []byte{}, err
}
return c, fmt.Errorf("expected value for %v element, got %T type %v instead", d.StartEl.Name.Local, t, t)
default:
return c, fmt.Errorf("expected value for %v element, got %T type %v instead", d.StartEl.Name.Local, t, t)
}

t, e = d.Decoder.Token()
if e != nil {
return c, e
}

if ev, ok := t.(xml.EndElement); ok {
if ev == d.StartEl.End() {
return c, true, err
if ev == endElement {
return c, err
}
}

return c, done, fmt.Errorf("expected value for %v element, got %T type %v instead", d.StartEl.Name.Local, t, t)
return c, fmt.Errorf("expected end element %v, got %T type %v instead", endElement, t, t)
}

// FetchRootElement takes in a decoder and returns the first start element within the xml body.
Expand Down
12 changes: 6 additions & 6 deletions encoding/xml/xml_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ func TestXMLNodeDecoder_Value(t *testing.T) {
},
"no value": {
responseBody: bytes.NewReader([]byte(`<Response></Response>`)),
expectedDone: true,
expectedValue: []byte{},
},
"self-closing": {
responseBody: bytes.NewReader([]byte(`<Response />`)),
expectedValue: []byte{},
},
"empty body": {
responseBody: bytes.NewReader([]byte(``)),
Expand All @@ -186,7 +190,7 @@ func TestXMLNodeDecoder_Value(t *testing.T) {
}
}
nodeDecoder := WrapNodeDecoder(xmlDecoder, st)
token, done, err := nodeDecoder.Value()
token, err := nodeDecoder.Value()
if err != nil {
if len(c.expectedError) == 0 {
t.Fatalf("Expected no error, got %v", err)
Expand All @@ -197,10 +201,6 @@ func TestXMLNodeDecoder_Value(t *testing.T) {
}
}

if e, a := c.expectedDone, done; e != a {
t.Fatalf("expected a valid end element token for the xml document, got none")
}

if diff := cmp.Diff(c.expectedValue, token); len(diff) != 0 {
t.Fatalf("Found diff : (-expected,+actual), \n %v", diff)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/awslabs/smithy-go
module github.com/aws/smithy-go

go 1.14

Expand Down
2 changes: 1 addition & 1 deletion logging/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"regexp"
"testing"

"github.com/awslabs/smithy-go/logging"
"github.com/aws/smithy-go/logging"
)

func TestNewStandardLogger(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package middleware
import (
"context"

"github.com/awslabs/smithy-go/logging"
"github.com/aws/smithy-go/logging"
)

// loggerKey is the context value key for which the logger is associated with.
Expand Down
4 changes: 2 additions & 2 deletions middleware/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"io/ioutil"
"testing"

"github.com/awslabs/smithy-go/logging"
"github.com/awslabs/smithy-go/middleware"
"github.com/aws/smithy-go/logging"
"github.com/aws/smithy-go/middleware"
)

type mockWithContextLogger struct {
Expand Down
2 changes: 1 addition & 1 deletion ptr/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"text/template"

"github.com/awslabs/smithy-go/ptr"
"github.com/aws/smithy-go/ptr"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion rand/uuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"testing"

"github.com/awslabs/smithy-go/rand"
"github.com/aws/smithy-go/rand"
)

func TestUUID(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion testing/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sort"
"strings"

"github.com/awslabs/smithy-go/testing/xml"
"github.com/aws/smithy-go/testing/xml"

"github.com/google/go-cmp/cmp"
)
Expand Down
2 changes: 1 addition & 1 deletion transport/http/checksum_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/awslabs/smithy-go/middleware"
"github.com/aws/smithy-go/middleware"
)

const contentMD5Header = "Content-Md5"
Expand Down
4 changes: 2 additions & 2 deletions transport/http/checksum_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"
"testing"

smithyio "github.com/awslabs/smithy-go/io"
"github.com/awslabs/smithy-go/middleware"
smithyio "github.com/aws/smithy-go/io"
"github.com/aws/smithy-go/middleware"
)

func TestChecksumMiddleware(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions transport/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"net/http"

smithy "github.com/awslabs/smithy-go"
"github.com/awslabs/smithy-go/middleware"
smithy "github.com/aws/smithy-go"
"github.com/aws/smithy-go/middleware"
)

// ClientDo provides the interface for custom HTTP client implementations.
Expand Down
2 changes: 1 addition & 1 deletion transport/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"testing"

smithy "github.com/awslabs/smithy-go"
smithy "github.com/aws/smithy-go"
)

func TestClientHandler_Handle(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion transport/http/deserailize_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"strconv"

"github.com/awslabs/smithy-go/middleware"
"github.com/aws/smithy-go/middleware"
)

func ExampleResponse_deserializeMiddleware() {
Expand Down
2 changes: 1 addition & 1 deletion transport/http/middleware_close_response_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/awslabs/smithy-go/middleware"
"github.com/aws/smithy-go/middleware"
)

// AddErrorCloseResponseBodyMiddleware adds the middleware to automatically
Expand Down
2 changes: 1 addition & 1 deletion transport/http/middleware_content_length.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/awslabs/smithy-go/middleware"
"github.com/aws/smithy-go/middleware"
)

// ComputeContentLength provides a middleware to set the content-length
Expand Down
2 changes: 1 addition & 1 deletion transport/http/middleware_content_length_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/awslabs/smithy-go/middleware"
"github.com/aws/smithy-go/middleware"
)

func TestContentLengthMiddleware(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion transport/http/middleware_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/awslabs/smithy-go/middleware"
"github.com/aws/smithy-go/middleware"
)

type headerValue struct {
Expand Down
Loading