Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Format code. #69

Merged
merged 1 commit into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 7 additions & 9 deletions brokers/unified/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func createMocks() *mocks {
cb.On("PubStarted")
cb.On("PrintPlan", mock.AnythingOfType("[]model.PluginMeta"))
cb.On("CloseConsumers")
cb.On("PubDone", mock.AnythingOfType("string"))
cb.On("PubDone", mock.AnythingOfType("string"))
return &mocks{
cb: cb,
u: u,
Expand Down Expand Up @@ -719,8 +719,7 @@ func TestBroker_processPlugins(t *testing.T) {
ID: "test id",
APIVersion: "v2",
Spec: model.PluginMetaSpec{
Extensions: []string{
},
Extensions: []string{},
},
}},
},
Expand All @@ -736,8 +735,7 @@ func TestBroker_processPlugins(t *testing.T) {
ID: "test id",
APIVersion: "v2",
Spec: model.PluginMetaSpec{
Extensions: []string{
},
Extensions: []string{},
},
}},
},
Expand Down Expand Up @@ -1173,14 +1171,14 @@ func TestBroker_getPluginMetas(t *testing.T) {
name: "Supports custom reference address",
args: args{
fqns: []model.PluginFQN{
{
Reference: "http://myregistry.com/plugins/myplugin/meta.yaml",
}},
{
Reference: "http://myregistry.com/plugins/myplugin/meta.yaml",
}},
defaultRegistry: "",
},
want: want{
errRegexp: nil,
fetchURL: "http://myregistry.com/plugins/myplugin/meta.yaml",
fetchURL: "http://myregistry.com/plugins/myplugin/meta.yaml",
},
mocks: successMock,
},
Expand Down
2 changes: 1 addition & 1 deletion brokers/unified/vscode/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (b *brokerImpl) injectRemotePlugin(plugin model.ChePlugin, archivesPaths []
if err != nil {
return err
}

pluginArchivePath := filepath.Join(pluginFolderPath, b.generatePluginArchiveName(plugin, archive))
b.PrintDebug("Copying VS Code extension '%s' from '%s' to '%s'", plugin.ID, archive, pluginArchivePath)
err = b.ioUtil.CopyFile(archive, pluginArchivePath)
Expand Down
6 changes: 3 additions & 3 deletions brokers/unified/vscode/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
package vscode

import (
"strings"
"bytes"
"errors"
"fmt"
"io/ioutil"
"net/http"
"path/filepath"
"strings"
"testing"

tests "github.com/eclipse/che-plugin-broker/brokers/test"
Expand Down Expand Up @@ -569,15 +569,15 @@ func expectedPluginsWithSingleRemotePluginWithSeveralExtensions(usedLocalhost bo
Value: "4242",
},
}
expectedPlugin.Endpoints = []model.Endpoint {
expectedPlugin.Endpoints = []model.Endpoint{
model.Endpoint{
Name: "randomString1234567890",
Public: false,
TargetPort: 4242,
},
}
expectedPlugin.WorkspaceEnv = append(expectedPlugin.WorkspaceEnv, model.EnvVar{
Name: "THEIA_PLUGIN_REMOTE_ENDPOINT_" + strings.ReplaceAll(pluginPublisher + "_" + pluginName + "_" + pluginVersion, " ", "_"),
Name: "THEIA_PLUGIN_REMOTE_ENDPOINT_" + strings.ReplaceAll(pluginPublisher+"_"+pluginName+"_"+pluginVersion, " ", "_"),
Value: "ws://randomString1234567890:4242",
})
}
Expand Down
42 changes: 21 additions & 21 deletions brokers/unified/vscode/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
package vscode

import (
"strings"
"github.com/eclipse/che-plugin-broker/common"
cmock "github.com/eclipse/che-plugin-broker/common/mocks"
"strconv"
"strings"
"testing"

"github.com/eclipse/che-plugin-broker/model"
Expand All @@ -30,8 +30,8 @@ const (

func TestAddPluginRunnerRequirements(t *testing.T) {
type args struct {
plugin model.ChePlugin
rand common.Random
plugin model.ChePlugin
rand common.Random
useLocalhost bool
}
tests := []struct {
Expand All @@ -47,8 +47,8 @@ func TestAddPluginRunnerRequirements(t *testing.T) {
},
want: model.ChePlugin{
Publisher: pluginPublisher,
Name: pluginName,
Version: pluginVersion,
Name: pluginName,
Version: pluginVersion,
Containers: []model.Container{
{
Name: "pluginsidecar",
Expand All @@ -70,7 +70,7 @@ func TestAddPluginRunnerRequirements(t *testing.T) {
Name: "THEIA_PLUGIN_ENDPOINT_PORT",
Value: strconv.Itoa(4040),
},
{ Name: "THEIA_PLUGINS",
{Name: "THEIA_PLUGINS",
Value: "local-dir:///plugins/sidecars/test_publisher_test_name_tv",
},
},
Expand All @@ -88,14 +88,14 @@ func TestAddPluginRunnerRequirements(t *testing.T) {
{
name: "Check that all configuration needed for plugin runner is added, when plugins are on the Theia host",
args: args{
plugin: generateDefaultTestChePlugin(),
rand: generateMockOfRandom("newTestEndpoint", 4040),
plugin: generateDefaultTestChePlugin(),
rand: generateMockOfRandom("newTestEndpoint", 4040),
useLocalhost: true,
},
want: model.ChePlugin{
Publisher: pluginPublisher,
Name: pluginName,
Version: pluginVersion,
Name: pluginName,
Version: pluginVersion,
Containers: []model.Container{
{
Name: "pluginsidecar",
Expand All @@ -108,7 +108,7 @@ func TestAddPluginRunnerRequirements(t *testing.T) {
},
MountSources: true,
Env: []model.EnvVar{
{ Name: "THEIA_PLUGINS",
{Name: "THEIA_PLUGINS",
Value: "local-dir:///plugins/sidecars/test_publisher_test_name_tv",
},
},
Expand All @@ -127,7 +127,7 @@ func TestAddPluginRunnerRequirements(t *testing.T) {

func TestAddExtension(t *testing.T) {
type args struct {
plugin model.ChePlugin
plugin model.ChePlugin
}
tests := []struct {
name string
Expand All @@ -139,8 +139,8 @@ func TestAddExtension(t *testing.T) {
args: args{
plugin: model.ChePlugin{
Publisher: pluginPublisher,
Name: pluginName,
Version: pluginVersion,
Name: pluginName,
Version: pluginVersion,
Containers: []model.Container{
{
Name: "pluginsidecar",
Expand Down Expand Up @@ -174,10 +174,10 @@ func TestAddExtension(t *testing.T) {
},
},
},
want: model.ChePlugin{
want: model.ChePlugin{
Publisher: pluginPublisher,
Name: pluginName,
Version: pluginVersion,
Name: pluginName,
Version: pluginVersion,
Containers: []model.Container{
{
Name: "pluginsidecar",
Expand Down Expand Up @@ -209,9 +209,9 @@ func TestAddExtension(t *testing.T) {
TargetPort: defaultPort,
},
},
WorkspaceEnv: []model.EnvVar {
WorkspaceEnv: []model.EnvVar{
model.EnvVar{
Name: "THEIA_PLUGIN_REMOTE_ENDPOINT_" + strings.ReplaceAll(pluginPublisher + "_" + pluginName + "_" + pluginVersion, " ", "_"),
Name: "THEIA_PLUGIN_REMOTE_ENDPOINT_" + strings.ReplaceAll(pluginPublisher+"_"+pluginName+"_"+pluginVersion, " ", "_"),
Value: "ws://" + defaultEndpointName + ":" + strconv.Itoa(defaultPort),
},
},
Expand All @@ -229,8 +229,8 @@ func TestAddExtension(t *testing.T) {
func generateDefaultTestChePlugin() model.ChePlugin {
return model.ChePlugin{
Publisher: pluginPublisher,
Name: pluginName,
Version: pluginVersion,
Name: pluginName,
Version: pluginVersion,
Containers: []model.Container{
{
Name: "pluginsidecar",
Expand Down
4 changes: 2 additions & 2 deletions cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var (
// instead of the Kubernetes service name to build Theia or VSCode plugin
// endpoint URL
// True by default since until now all remote VS Code or Theia plugin containers
// are started on the same POD as the Theia IDE container
// are started on the same POD as the Theia IDE container
UseLocalhostInPluginUrls = true

// OnlyApplyMetadataActions configures the broker to only apply metadata-related
Expand Down Expand Up @@ -185,7 +185,7 @@ func Print() {
log.Printf(" Workspace: %s", RuntimeID.Workspace)
log.Printf(" Environment: %s", RuntimeID.Environment)
log.Printf(" OwnerId: %s", RuntimeID.OwnerId)
if (SelfSignedCertificateFilePath != "") {
if SelfSignedCertificateFilePath != "" {
log.Printf(" Self signed certificate %s", SelfSignedCertificateFilePath)
}
}
Expand Down
6 changes: 3 additions & 3 deletions common/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
package common

import (
"net/http"
"log"
"net/http"
Copy link
Contributor

@nickboldt nickboldt Aug 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are there two separate lists here so that log and net/http are listed before the crypto stuff?


"crypto/tls"
"crypto/x509"
"github.com/eclipse/che-go-jsonrpc"
"github.com/eclipse/che-go-jsonrpc/event"
"github.com/eclipse/che-go-jsonrpc/jsonrpcws"
"crypto/x509"
"io/ioutil"
"crypto/tls"
)

type tunnelBroadcaster struct {
Expand Down
4 changes: 2 additions & 2 deletions common/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Random interface {
}

type RandomImpl struct {
rand *rand.Rand
rand *rand.Rand
}

func NewRand() Random {
Expand All @@ -47,7 +47,7 @@ func (r *RandomImpl) Int(n int) int {
}

func (r *RandomImpl) IntFromRange(from int, to int) int {
return from + r.rand.Intn(to - from)
return from + r.rand.Intn(to-from)
}

func (r *RandomImpl) String(length int) string {
Expand Down
6 changes: 3 additions & 3 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ type PluginMetaSpec struct {
}

type PluginFQN struct {
Registry string `json:"registry,omitempty" yaml:"registry,omitempty"`
ID string `json:"id" yaml:"id"`
Reference string `json:"reference" yaml:"reference"`
Registry string `json:"registry,omitempty" yaml:"registry,omitempty"`
ID string `json:"id" yaml:"id"`
Reference string `json:"reference" yaml:"reference"`
}

type Endpoint struct {
Expand Down
20 changes: 10 additions & 10 deletions utils/ioutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
package utils

import (
"path"
"mime"
"archive/tar"
"archive/zip"
"bufio"
Expand All @@ -23,9 +21,11 @@ import (
"io"
"io/ioutil"
"log"
"mime"
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
)
Expand Down Expand Up @@ -72,41 +72,41 @@ func (util *impl) Download(URL string, destPath string, useContentDisposition bo
filePath, filename := filepath.Split(destPath)

if useContentDisposition {
fromHeader := func () (found bool, filename string) {
fromHeader := func() (found bool, filename string) {
dispo := resp.Header.Get("Content-Disposition")
if dispo == "" {
return
return
}

_, params, err := mime.ParseMediaType(dispo);
_, params, err := mime.ParseMediaType(dispo)
if err != nil {
return
}

contentDispoFilename := params["filename"]
if strings.HasSuffix(contentDispoFilename, "/") || strings.Contains(contentDispoFilename, "\x00") {
return
return
}
contentDispoFilename = path.Base(path.Clean("/" + contentDispoFilename))
if contentDispoFilename == "." || contentDispoFilename == "/" {
return
}
return true, contentDispoFilename
}

if found, contentDispoFilename := fromHeader(); found {
filename = contentDispoFilename
}
}

destPath = filepath.Join(filePath, filename)

out, err := os.Create(destPath)
if err != nil {
return "", err
}
defer Close(out)

_, err = io.Copy(out, resp.Body)
if err != nil {
return "", err
Expand Down
Loading