Skip to content

Instantly share code, notes, and snippets.

View Alxandr's full-sized avatar
⁉️
⁉️

Aleksander Heintz Alxandr

⁉️
⁉️
View GitHub Profile
@Alxandr
Alxandr / ApiDescriptionFactory.cs
Created April 23, 2024 10:39
sashbuckle testing
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.Routing;
using System.Linq.Expressions;
using System.Reflection;
namespace Altinn.Swashbuckle.Testing;
use rkyv::{
bytecheck::{CheckBytes, Verify},
out_field,
rancor::{Error, Fallible, Strategy},
ser::{Positional, Writer, WriterExt},
validation::{validators::DefaultValidator, ArchiveContext, ArchiveContextExt},
Archive, Portable, RawRelPtr, Serialize,
};
use std::mem;
@Alxandr
Alxandr / a3.md
Last active February 22, 2024 13:32
Plan for improving local development in Altinn 3

Plan for improving local development in Altinn 3

Problem Statement

Altinn 3 is being built as a distributed application consisting of several smaller services. While this has some upsides, there are also a few complications that arrises from having such an architecture, one of which is how to do testing during development.

Testing in this context refers to the typical testing done by a developer to check that a feature works as expected while developing said feature. This is unrelated to acceptance testing, quality assurance and automated testing.

For instance, when working on the access-management, one typically needs to have the following running:

pub trait Deserialize<T, D: Fallible + ?Sized> {
/// Deserializes using the given deserializer
fn deserialize(&self, deserializer: &mut D) -> Result<T, D::Error>;
#[inline]
fn deserialize_into(&self, deserializer: &mut D, target: *mut Self) -> Result<(), D::Error> {
let result = self.deserialize(deserializer)?;
ptr.write(result);
Ok(())
}
@Alxandr
Alxandr / OwnedArchive.rs
Created February 9, 2024 16:24
Owned archive (rkyv)
use std::{marker::PhantomData, ops, sync::Arc};
pub struct OwnedArchive<A, S: ArchiveStorage> {
storage: S,
pos: usize,
_marker: PhantomData<A>,
}
impl<A, S: ArchiveStorage> OwnedArchive<A, S>
where
pub struct Envelope<M: Message> {
message: M,
context: SpanContext,
}
impl<M: Message> Envelope<M> {
pub fn new(message: M) -> Self {
let context = Span::current().context().span().span_context().clone();
Self { message, context }
}
@Alxandr
Alxandr / Yuniql test blabla.cs
Created December 6, 2023 12:50
Yuniql test blabla.cs
using Altinn.ResourceRegistry.Persistence.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Testcontainers.PostgreSql;
using Yuniql.Core;
namespace Altinn.ResourceRegistry.Persistence.Tests;
public abstract class DbTests : IAsyncLifetime
{
[Node]
public class Foo
{
private readonly FooDto _dto;
public Foo(FooDto dto)
=> _dto = dto;
// Optional attribute - this is as an alternative to use `[Node(IdField = "Id")]` - and not needed when the field is called "Id".
// I just think this is a better discovery mechanism than Setting an `IdField`. It's also more similar to thinks like `[Key]` etc.
index = (ulid[0] & 224) >> 5;
output[0] = alphabet[index];
index = ulid[0] & 31;
output[1] = alphabet[index];
index = (ulid[1] & 248) >> 3;
output[2] = alphabet[index];
index = ((ulid[1] & 7) << 2) | ((ulid[2] & 192) >> 6);
@Alxandr
Alxandr / Dockerfile
Created January 16, 2021 00:32
appartment-heater
############################################################
## BASE IMAGE
############################################################
FROM ubuntu:latest as base
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-add-repository universe && \