text:
// Copyright Project Harbor Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package registry

import (
	"encoding/json"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/stretchr/testify/suite"

	"github.com/goharbor/harbor/src/controller/repository"
	"github.com/goharbor/harbor/src/controller/tag"
	"github.com/goharbor/harbor/src/pkg/repository/model"
	model_tag "github.com/goharbor/harbor/src/pkg/tag/model/tag"
	repotesting "github.com/goharbor/harbor/src/testing/controller/repository"
	tagtesting "github.com/goharbor/harbor/src/testing/controller/tag"
	"github.com/goharbor/harbor/src/testing/mock"
)

type tagTestSuite struct {
	suite.Suite
	originalRepoCtl repository.Controller
	repoCtl         *repotesting.Controller
	originalTagCtl  tag.Controller
	tagCtl          *tagtesting.FakeController
}

func (c *tagTestSuite) SetupSuite() {
	c.originalRepoCtl = repository.Ctl
	c.originalTagCtl = tag.Ctl
}

func (c *tagTestSuite) SetupTest() {
	c.repoCtl = &repotesting.Controller{}
	repository.Ctl = c.repoCtl
	c.tagCtl = &tagtesting.FakeController{}
	tag.Ctl = c.tagCtl
}

func (c *tagTestSuite) TearDownTest() {
}

func (c *tagTestSuite) TearDownSuite() {
	repository.Ctl = c.originalRepoCtl
	tag.Ctl = c.originalTagCtl
}

func (c *tagTestSuite) TestListTag() {
	c.SetupTest()
	req := httptest.NewRequest(http.MethodGet, "/v2/library/hello-world/tags/list", nil)
	var w *httptest.ResponseRecorder
	mock.OnAnything(c.repoCtl, "GetByName").Return(&model.RepoRecord{
		RepositoryID: 1,
		Name:         "library/hello-world",
	}, nil)
	c.tagCtl.On("List").Return([]*tag.Tag{
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v1",
			},
		},
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v2",
			},
		},
	}, nil)
	w = httptest.NewRecorder()
	newTagHandler().ServeHTTP(w, req)
	c.Equal(http.StatusOK, w.Code)
	var tagsAPIResponse struct {
		Name string   `json:"name"`
		Tags []string `json:"tags"`
	}
	decoder := json.NewDecoder(w.Body)
	err := decoder.Decode(&tagsAPIResponse)
	c.Nil(err)
	c.Equal(2, len(tagsAPIResponse.Tags))
}

func (c *tagTestSuite) TestListTagPagination1() {
	c.SetupTest()
	req := httptest.NewRequest(http.MethodGet, "/v2/hello-world/tags/list?n=1", nil)
	var w *httptest.ResponseRecorder
	mock.OnAnything(c.repoCtl, "GetByName").Return(&model.RepoRecord{
		RepositoryID: 1,
		Name:         "hello-world",
	}, nil)
	c.tagCtl.On("List").Return([]*tag.Tag{
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v1",
			},
		},
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v2",
			},
		},
	}, nil)
	w = httptest.NewRecorder()
	newTagHandler().ServeHTTP(w, req)
	c.Equal(http.StatusOK, w.Code)
	var ctlg struct {
		Name string   `json:"name"`
		Tags []string `json:"tags"`
	}
	decoder := json.NewDecoder(w.Body)
	err := decoder.Decode(&ctlg)
	c.Nil(err)
	c.Equal(1, len(ctlg.Tags))
	c.Equal("v1", ctlg.Tags[0])
}

func (c *tagTestSuite) TestListTagPagination2() {
	c.SetupTest()
	req := httptest.NewRequest(http.MethodGet, "/v2/hello-world/tags/list?n=3", nil)
	var w *httptest.ResponseRecorder
	mock.OnAnything(c.repoCtl, "GetByName").Return(&model.RepoRecord{
		RepositoryID: 1,
		Name:         "hello-world",
	}, nil)
	c.tagCtl.On("List").Return([]*tag.Tag{
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v1",
			},
		},
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v2",
			},
		},
	}, nil)
	w = httptest.NewRecorder()
	newTagHandler().ServeHTTP(w, req)
	c.Equal(http.StatusOK, w.Code)
	var ctlg struct {
		Name string   `json:"name"`
		Tags []string `json:"tags"`
	}
	decoder := json.NewDecoder(w.Body)
	err := decoder.Decode(&ctlg)
	c.Nil(err)
	c.Equal(2, len(ctlg.Tags))
	c.Equal("v2", ctlg.Tags[1])
}

func (c *tagTestSuite) TestListTagPagination3() {
	c.SetupTest()
	req := httptest.NewRequest(http.MethodGet, "/v2/hello-world/tags/list?last=v1&n=1", nil)
	var w *httptest.ResponseRecorder
	mock.OnAnything(c.repoCtl, "GetByName").Return(&model.RepoRecord{
		RepositoryID: 1,
		Name:         "hello-world",
	}, nil)
	c.tagCtl.On("List").Return([]*tag.Tag{
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v1",
			},
		},
		{
			Tag: model_tag.Tag{
				RepositoryID: 1,
				Name:         "v2",
			},
		},
	}, nil)
	w = httptest.NewRecorder()
	newTagHandler().ServeHTTP(w, req)
	c.Equal(http.StatusOK, w.Code)
	var ctlg struct {
		Name string   `json:"name"`
		Tags []string `json:"tags"`
	}
	decoder := json.NewDecoder(w.Body)
	err := decoder.Decode(&ctlg)
	c.Nil(err)
	c.Equal(1, len(ctlg.Tags))
	c.Equal("v2", ctlg.Tags[0])
}

func TestTagTestSuite(t *testing.T) {
	suite.Run(t, &tagTestSuite{})
}

repository: goharbor/harbor

repo_name: goharbor/harbor


text:
############## /home/jrs/cvs/oe/org.openembedded.dev/packages/linux/xanadux-un-2.6_2.6.12.bb ###############

DESCRIPTION = "Xanadux HTC-Universal kernel based on the hh 2.6.12"
LICENSE = "GPL"
PR="r2"

SRC_URI = "cvs://anonymous@xanadux.cvs.sourceforge.net/cvsroot/xanadux;method=pserver;module=linux-2.6-xda;tag=K2-6-12-hh2-xda0-un0"
S = "${WORKDIR}/linux-2.6-xda"

COMPATIBLE_HOST = "arm.*-linux"
COMPATIBLE_MACHINE = "htc-universal"

inherit kernel

do_configure() {
        cp arch/arm/configs/htcuniversal_defconfig .config || die "No default configuration for ${MACHINE} available."
        yes '' | oe_runmake oldconfig
}

###############################################################
# put into deploy directory
#
do_deploy() {
        install -d ${DEPLOY_DIR_IMAGE}
        install -m 0644 arch/${ARCH}/boot/${KERNEL_IMAGETYPE} ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-${PV}-${MACHINE}-${DATETIME}.bin
        tar -cvzf ${DEPLOY_DIR_IMAGE}/modules-${KERNEL_VERSION}-${MACHINE}.tgz -C ${D} lib
}

do_deploy[dirs] = "${S}"

addtask deploy before do_package after do_install

license: MIT

repository: jdegges/gumstix-pip-oe

license_type: permissive

repo_name: jdegges/gumstix-pip-oe

branch_name: refs/heads/master


text:
## Add the following to your local.conf
## DISTRO_FEATURES_remove = "x11 wayland"
## PACKAGECONFIG_append_pn-qtmultimedia = " gstreamer010 "

DESCRIPTION = "A minimal qt5 image without X11"

LICENSE = "MIT"

include qt5-versions.inc

IMAGE_INSTALL_append = "\
    ${CORE_IMAGE_BASE_INSTALL} \
    firmware-imx-vpu-imx6q \
    firmware-imx-vpu-imx6d \
    gdb \
    dropbear \
    packagegroup-fsl-gstreamer \
    gstreamer \
    gst-plugins-base-app \
    gst-plugins-base \
    gst-plugins-good \
    gst-plugins-good-rtsp \
    gst-plugins-good-udp \
    gst-plugins-good-rtpmanager \
    gst-plugins-good-rtp \
    gst-plugins-good-video4linux2 \
    qtbase-fonts \
    qtbase-plugins \
    qtbase-tools \
    qtdeclarative \
    qtdeclarative-plugins \
    qtdeclarative-tools \
    qtdeclarative-qmlplugins \
    qtmultimedia \
    qtmultimedia-plugins \
    qtmultimedia-qmlplugins \
    qtsvg \
    qtsvg-plugins \
    qtsensors \
    qtimageformats-plugins \
    qtsystems \
    qtsystems-tools \
    qtsystems-qmlplugins \
    qtscript \
    qt3d \
    qt3d-examples \
    qt3d-qmlplugins \
    qt3d-tools \
    qtwebkit \
    qtwebkit-qmlplugins \
    cinematicexperience \
    util-linux \
    imx-test \
    strace \
"

inherit core-image

export IMAGE_BASENAME = "reach-image-qt5"

branch_name: HEAD

extension: bb